#include <iostream>
#include<map>
#include <gtest/gtest.h>

/*
    全局单元测试，进行测试前的初始化，和测试后的资源清理
*/

class Envir : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout<<"进行单元测试前的初始化"<<std::endl;
    }
    virtual void TearDown() override
    {
        std::cout<<"进行单元测试后的测试清理"<<std::endl;
    }
};
TEST(Envir, test1)
{
    std::cout<<"全局单元测试--test1"<<std::endl;
}
TEST(Envir, test2)
{
    std::cout<<"全局单元测试--test2"<<std::endl;
}


std::map<std::string, std::string> _map;
class MapEnvir:public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout<<"初始化全局变量 map"<<std::endl;
        _map.insert(std::make_pair("hello", "你好"));
        _map.insert(std::make_pair("happy", "开心"));
    }
    virtual void TearDown() override
    {
        std::cout<<"释放全局变量 map"<<std::endl;
        _map.~map();
    }
};
TEST(MapEnvir, test1)
{
    // ASSERT_EQ(_map.find("happy"), 1);
    ASSERT_EQ(_map.size(), 1);
    _map.erase("happy");
}
TEST(MapEnvir, test2)
{
    // ASSERT_EQ(_map.find("happy"), 1);
    ASSERT_EQ(_map.size(), 1);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new Envir);
    testing::AddGlobalTestEnvironment(new MapEnvir);
    RUN_ALL_TESTS();
}
